import { defineStore } from 'pinia'
import { ref } from 'vue'
import {getGoodsList,getListNum} from "@/api/good";

export const useGoodsStore = defineStore(
    'goods-store',
    () => {
       const type=ref('')
       const brand=ref('')
       let total=ref(0)
       let goodsList=ref([])
       const nowGoodsId=ref(0)  //进入详情页面时获取商品id

       const GetList = async (type,brand,page,pageSize)=>{
         const res= await getGoodsList(type,brand,page,pageSize)
          goodsList.value=res.data.data
       }

       const GetNum=async (type,brand)=>{
           const  res=await getListNum(type,brand)
           total.value=res.data.data
       }

        return {
            type,
            brand,
            total,
            nowGoodsId,
            goodsList,
            GetList,
            GetNum
        }
    },
    {
        persist: true
    }
)
